﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using NTQOnlineExam.Services.EntityFW.Entity;
using NTQOnlineExam.Services.ReportService.Order;
using NTQOnlineExam.Services.ReportService.Portfolio;
using NTQOnlineExam.Services.SearchCriteria;
using NTQOnlineExamFrontend.Helpers;
using NTQOnlineExamFrontend.Models;

namespace NTQOnlineExamFrontend.Controllers
{
    [Authorize]
    public class OrderController : Controller
    {
        private readonly IOrderReportService _orderReportService;
        public OrderController(IOrderReportService orderReportService)
        {
            _orderReportService = orderReportService;
        }

        [HttpGet]
        public ActionResult OrderHistory()
        {
            IList<BreadcrumItem> breadcrumItems = new List<BreadcrumItem>();
            breadcrumItems.Add(new BreadcrumItem("Personal", "/Order/OrderHistory", false));
            breadcrumItems.Add(new BreadcrumItem("Order History", string.Empty, true));
            ViewData["Breadcrumb"] = breadcrumItems;

            return View();
           
        }

        [HttpGet]
        public ActionResult Search(string keyword, int pageIndex)
        {
            int total = 0;

            var sortItems = Utility.GetSortItems(Request);
            var orders = _orderReportService.GetCurrentUserOrderHistory(sortItems, OrderHistoryViewModel.PageSize,pageIndex,out total);
            var model = new OrderHistoryViewModel() { Orders = orders, SelectedPage = pageIndex, TotalRecords = total };
            return PartialView("_OrderHistory",model);
        }

        public ActionResult OrderHistoryDetail(Guid orderId)
        {
            var order = _orderReportService.GetOrderById(orderId);
            var model = new OrderHistoryDetailViewModel() { Order = order};
            return View(model);
        }
       
    }
}
